package org.iteam.xlz.manager.timer;

import java.util.List;
import java.util.TimerTask;

import org.iteam.commons.utils.DateUtil;
import org.iteam.xlz.core.entity.messages.Notices;
import org.iteam.xlz.core.service.message.NoticeService;
import org.iteam.xlz.manager.utils.UmengDemo;

public class UmengTimerTask extends TimerTask{

	boolean testMode=true;
	//@Override
	public void run() {
		System.out.println("友盟推送定时任务开始执行。。。"+DateUtil.currentTime());
		List<Notices> notices=NoticeService.getInstance().getUnNoticed();
		
		for(Notices s:notices){
			UmengDemo demo=new UmengDemo("来自小礼子的消息",s.getTitle(),s.getContent(),s.getContent());
			try {
				if(0==s.getOs()){
					demo.sendAndroidBroadcast();
				}else
					if(1==s.getOs()){
						demo.sendIOSBroadcast();
					}else{
						demo.sendIOSBroadcast();
						demo.sendAndroidBroadcast();
					}
				s.setStatus(1);

				NoticeService.getInstance().update(s);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		System.out.println("友盟推送定时任务执行完毕。。。"+DateUtil.currentTime());
	}
}
